package com.cx.factory;

public interface Shape {
    /**
     * 绘制图形
     */
    void draw();
}

 class Triangle implements Shape{
    @Override
    public void draw() {
        System.out.println("绘制三角形");
    }
}
//绘制四边形实现类Square
/**
 * 绘制四边形
 */
 class Square implements Shape{
    @Override
    public void draw() {
        System.out.println("绘制四边形");
    }
}

class Circle implements Shape{
    @Override
    public void draw() {
        System.out.println("绘制圆形");
    }
}

class ShapeFactory {
    /**
     * 创建对象
     * @param type 对象类型
     * @return
     */
    public static Shape createBean(String type){
        Shape shape;
        switch (type.toLowerCase()){
            case "triangle":
                shape = new Triangle();
                break;
            case "square":
                shape = new Square();
                break;
            case "circle":
                shape = new Circle();
                break;
            default:
                shape = null;
        }
        return shape;
    }

    public static void main(String[] args) {
        //创建Triangle对象
        Shape triangle = ShapeFactory.createBean("triangle");
        triangle.draw();
        //创建Square对象
        Shape square = ShapeFactory.createBean("square");
        square.draw();
        Shape circle = ShapeFactory.createBean("circle");
        circle.draw();
    }
}